import './extend'

// 生成用户表
const Mock = require('mockjs')
// Mock.mock( url, post/get , 返回的数据)；
Mock.mock('/api/user/list', 'post', option=>{
  console.log(JSON.parse(option.body))
  return Mock.mock({
    "success": true,
    "msg": "操作成功！",
    "code": 0,
    "result": {
      "rows|20":[{  // 生成10~20条数据
        "id|+1": 1,   // id递增1
        roleName:Mock.Random.pick(["1", "2", "3", "4", "5"],1,5),  // 数组内随机一个值
        "roleCode": "100010",
        "description": '150302',
        "createBy": "jeecg",
        "createTime": new Date(),
        "updateBy|1": ["测试角色1", "测试角色2", "测试角色3", "测试角色4", "测试角色5"],
        "updateTime": '@now',
        "age|10-100":1,
      }],
      "total|100-200":100
    },
    "timestamp": '@now',
  });
})

//模拟新增用户
Mock.mock('/api/user/add','post',option=>{
  return Mock.mock({
    "success": true,
    "msg": "操作成功！",
    "code": 0,
    "timestamp": '@now',
    option
  })
})

//模拟删除用户
Mock.mock('/api/user/delete','post',option=>{
  console.log(option)
  return Mock.mock({
    "success": true,
    "msg": "操作成功！",
    "code": 0,
    "timestamp": '@now',
    option
  })
})


//TODO: 模拟获取菜单
//type:1=子系统 2=菜单目录 3=功能 4=自定义方法
Mock.mock('/api/menu','post',option=>{
  const body = JSON.parse(option.body)
  if (body.token == '123'){
    return Mock.mock({
      "success": true,
      "msg": "请求成功！",
      "code": 0,
      "timestamp": '@now',
      result:[
        {
          code:"@guid",
          title:'后台管理',
          icon:'el-icon-setting',
          type:1,
          pcode:null,
          path:'/admin',
          children:[
            {
              code:"@guid",
              title:'用户管理',
              icon:'el-icon-user',
              type:3,
              pcode:1,
              path:"/admin/user-manager"
            },
            {
              code:"@guid",
              title:'表单测试',
              icon:'el-icon-user',
              type:3,
              pcode:1,
              path:"/admin/form-edit-test"
            },
            {
              code:"@guid",
              title:'工作台',
              icon:'el-icon-user',
              type:3,
              pcode:1,
              path:"/admin/gzt"
            },
            {
              code:"@guid",
              title:'表格测试',
              icon:'el-icon-user',
              type:3,
              pcode:1,
              path:"/admin/grid-test"
            },
            {
              code:"@guid",
              title:'表格测试1',
              icon:'el-icon-user',
              type:3,
              pcode:1,
              path:"/admin/base-grid-test"
            },
            {
              code:"@guid",
              title:'test',
              icon:'el-icon-user',
              type:2,
              pcode:1,
              children:[
                {
                  code:"@guid",
                  title:'test1',
                  icon:'el-icon-user',
                  type:3,
                  pcode:1,
                  path:"/admin/user-manager"
                },
                {
                  code:"@guid",
                  title:'test2',
                  icon:'el-icon-user',
                  type:3,
                  pcode:1,
                  path:"/admin/user-manager"
                },
              ]
            },
          ]
        },
        {
          code:"@guid",
          title:'值班系统',
          icon:'el-icon-setting',
          type:1,
          pcode:null,
          path:'/',
          children:[
            {
              code:"@guid",
              title:'测试1',
              icon:'el-icon-user',
              type:3,
              pcode:1,
              path:"/home"
            },
            {
              code:"@guid",
              title:'测试2',
              icon:'el-icon-user',
              type:3,
              pcode:1,
              path:"/admin/user-manager"
            },
            {
              code:"@guid",
              title:'test',
              icon:'el-icon-user',
              type:2,
              pcode:1,
              children:[
                {
                  code:"@guid",
                  title:'test1',
                  icon:'el-icon-user',
                  type:3,
                  pcode:1,
                  path:"/admin/user-manager"
                },
                {
                  code:"@guid",
                  title:'test1',
                  icon:'el-icon-user',
                  type:3,
                  pcode:1,
                  path:"/admin/user-manager"
                },
                {
                  code:"@guid",
                  title:'test',
                  icon:'el-icon-user',
                  type:2,
                  pcode:1,
                  children:[
                    {
                      code:"@guid",
                      title:'test1',
                      icon:'el-icon-user',
                      type:3,
                      pcode:1,
                      path:"/admin/user-manager"
                    },
                    {
                      code:"@guid",
                      title:'test2',
                      icon:'el-icon-user',
                      type:3,
                      pcode:1,
                      path:"/admin/user-manager"
                    },
                  ]
                },
              ]
            },
          ]
        }
      ]
    })
  }else{
    return Mock.mock({
      "success": false,
      "msg": "登录失败！11111",
      "code": -1,
      "timestamp": '@now',
      option
    })
  }
})

Mock.mock('/user/save/img','post',data=>{
  console.log(data)
  return Mock.mock({
    "success": true,
    "msg": "请求成功！",
    "code": 0,
    "timestamp": '@now',
    "result":data
  })
})
